﻿@{
    ViewBag.Title = "WorkTypeForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script src="~/Content/scripts/utils/LeSoft-form.js"></script>
<script>
    var keyValue = request('keyValue');
    var parentId = "0";
    var organizeid = " @LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        initControl();
        //获取表单
       
    })
    //初始化控件


    function initControl() {

        
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==选择所属机构==",
            height: "250px",
            click: function (data) {
                organizeid = data.id;
                //加载部门
                $("#ResponseDept").ComboBoxTree({
                    url: "../../BaseManage/Department/GetOrganizeTreeJson?OrganizeId=" + organizeid,
                    description: "==请选择==",
                    height: 120,
                    allowSearch: true
                });
            }
        });
        $("#OrganizeId").ComboBoxSetValue(organizeid);

        //加载岗位
        $("#ExecRoleId").ComboBox({
            url: "../../BaseManage/Post/GetListJson" ,
            id: "RoleId",
            text: "FullName",
            description: "==请选择==",
            allowSearch: true
        });
        //加载部门
        $("#ResponseDept").ComboBoxTree({
            url: "../../BaseManage/Department/GetOrganizeTreeJson?OrganizeId=" + organizeid,           
            description: "==请选择==",
            height:120,
            allowSearch: true
        });

        //上级
        $("#ParentId").ComboBoxTree({
            url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeTreeJson",
            description: "==请选择==",
            height: "230px",
            allowSearch: true,
            click: function (item) {
                if (item.id != parentId) {
                    parentId = item.id;
                }
            }
        });
        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeEntity",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    parentId = data.parentId;
                }
            })

        };
      

    }



    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        if (!parentId) { parentId = "0" }
        postData["ParentId"] = parentId;
        postData["RoleType"] = 2;
        $.SaveForm({
            url: "../../PropertyManage/CS_DeviceMaintance/SaveWorkTypeForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid"); 
                dialogClose();
            }
        });

    }

</script>
<div style="margin-top: 20px; margin-right: 30px;">
    
    <table class="form" >
        <tr>
            <th class="formTitle">上级</th>
            <td class="formValue">
                <div id="ParentId" type="selectTree" class="ui-select" isvalid="yes"></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">种类名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Name" type="text" class="form-control" onblur="ExistField(this.id, '../../SystemManage/Task/ExistCodeOrName')" placeholder="请输入种类名称" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">种类编号<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Code" type="text" class="form-control"  placeholder="请输入种类编号" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">所属机构</td>
            <td class="formValue">
                <div id="OrganizeId" type="selectTree" class="ui-select" ></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">执行岗位<font face="宋体">*</font></td>
            <td class="formValue">
                <div id="ExecRoleId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">责任部门</td>
            <td class="formValue">
                <div id="ResponseDept" type="selectTree" class="ui-select" ></div>
            </td>
        </tr>
       

        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">
                备注
            </th>
            <td class="formValue">
                <textarea id="Memo" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>